﻿using System.Collections.Generic;

namespace Core
{
    /// <summary>
    /// 字符映射字典
    /// 
    /// </summary>
    public class InfixDict
    {
        private readonly Dictionary<string, string> dict1 = new();
        private readonly Dictionary<string, Dictionary<string, string>> dict2 = new();

        private string strFormat;
        public InfixDict(string format)
        {
            strFormat = format;
        }

        public string this[string k1]
        {
            get
            {
                if (!dict1.ContainsKey(k1))
                {
                    dict1[k1] = string.Format(strFormat, k1);
                }
                return dict1[k1];
            }
        }

        public string this[string k1, string k2]
        {
            get
            {
                if (!dict2.ContainsKey(k1))
                {
                    dict2[k1] = new Dictionary<string, string>();
                }
                var d = dict2[k1];
                if (!d.ContainsKey(k2))
                {
                    d[k2] = string.Format(strFormat, k1, k2);
                }
                return d[k2];
            }
        }

        public void Clear()
        {
            dict1.Clear();
            dict2.Clear();
        }
    }
}
